package com.ticket.sass.provider.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.provider.business.ResourceBusiness;
import com.ticket.sass.provider.business.impl.ResourceBusinessImpl;
import com.ticket.sass.provider.dto.input.resource.ResourceListInput;
import com.ticket.sass.provider.dto.input.resource.ResourceAddInput;
import com.ticket.sass.provider.dto.input.resource.ResourceUpdInput;
import com.ticket.sass.provider.dto.output.resource.RecursionResourceOutput;
import com.ticket.sass.provider.dto.output.resource.ResourceListOutput;
import com.ticket.sass.provider.model.ResultModel;
import com.ticket.sass.provider.service.PageModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 权限资源控制层
 * @author ywb
 * @date 2021-10-16 14:57
 */
@Slf4j
@ApiSupport(order = 903)
@Api(tags = "资源-模块")
@RestController
@RequestMapping("/resource")
public class ResourceController {
    final ResourceBusiness resourceBusiness;
    public ResourceController(ResourceBusinessImpl resourceBusiness) {
        this.resourceBusiness = resourceBusiness;
    }
    
    @GetMapping
    @ApiOperation("资源列表")
    public ResultModel<PageModel<ResourceListOutput>> getCinema(
        @Valid ResourceListInput input
    ) {
        return ResultModel.success(
            resourceBusiness.list(input)
        );
    }
    
    @PostMapping
    @ApiOperation(value = "新增资源", notes = "新增资源")
    public ResultModel<String> addResource(
        @RequestBody @Valid ResourceAddInput input
    ) {
        resourceBusiness.saveResource(input);
        return ResultModel.success();
    }
    
    @PutMapping
    @ApiOperation(value = "修改资源", notes = "修改资源")
    public ResultModel<String> updResource(
        @RequestBody @Valid ResourceUpdInput input
    ) {
        resourceBusiness.updResource(input);
        return ResultModel.success();
    }
    
    @GetMapping("/recursion")
    @ApiOperation("资源层级列表")
    public ResultModel<List<RecursionResourceOutput>> recursionList(
    ) {
        return ResultModel.success(
            resourceBusiness.recursionList()
        );
    }
}